package com.movie.controller;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.movie.beans.MovieBeans;
import com.movie.dao.MovieDao;

public class MovieAction implements Action {
	int type;
	MovieBeans mb = new MovieBeans();
	MovieDao md = new MovieDao();

	public MovieAction(int type) {
		this.type = type;
	}

	public Forward execute(HttpServletRequest request,
			HttpServletResponse response) {
		Forward forward = new Forward();
		if (type == 0) {
			ArrayList<MovieBeans> list = new ArrayList<MovieBeans>();
			String test;
			list = md.viewrecentMovie();
			test = makeHTML1(list);
			System.out.println(test);
			
			request.setAttribute("test", test);
			
			forward.setPagePath("./main.jsp?page=movieSearch");
			forward.setRedirect(false);
			
		}
		

		return forward;
	}

	public void viewappointedMovie() {

	}

	public void searchMovie() {

	}

	// public ArrayList<MovieBeans> viewrecentMovie(){
	// ArrayList<MovieBeans> vrm= new ArrayList<MovieBeans>();
	// vrm = md.viewrecentMovie();

	// return vrm;

	// }
	public void viewhighMovie() {

	}

	public String makeHTML1(ArrayList<MovieBeans> list) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			sb.append("<div id = 'ms_c3' class = 'border lfloat'><img src ="+list.get(i).getImage()+ "></div>"
					+ "<div id = 'ms_c4' class = 'border rfloat'><br>배우 : "
					+ list.get(i).getActor()+ "<br>나라 : "+list.get(i).getCountry()
					+ "<br>감독 : "+list.get(i).getDirector()+"<br>"
					+ "줄거리 : "+list.get(i).getStory() +"<br></div>");
		}
		return sb.toString();
	}
}


